<template>
  <div class="app-container">
    <el-row :gutter="0">
      <!-- 树形的菜单，现在这里只有静态数据（后期如果相加动态的可以绑上数据） -->
      <el-col :xs="24" :sm="6" :md="5" :lg="4" class="drag-area" id="drag-area">
        <div style="text-align: center; color: #0fa8e7">数据选择</div>

        <el-tree
          :data="tree"
          accordion
          :props="defaultProps"
          highlight-current
          @node-click="handleNodeClick"
        >
        </el-tree>
        <div class="drag-tip" id="drag-tip"></div>
      </el-col>
      <el-col :xs="24" :sm="18" :md="18.7" :lg="20" id="drag-content">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <!-- <el-form-item label="学年名称" prop="schoolYearId">
        <el-select
          v-model="queryParams.schoolYearId"
          placeholder="请选择学年"
          clearable
          @change="searchTermByYear()"
          size="small"
          style="width: 240px" 
        >
          <el-option
            v-for="item in yearOptions"
            :key="item.index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学期名称" prop="termId">
        <el-select
          v-model="queryParams.termId"
          placeholder="请选择学期"
          clearable
          size="small"
          style="width: 240px"
          @change="searchCollegeByTerm()"
        >
          <el-option
            v-for="item in termNameOptions"
            :key="item.index"
            :label="item.termName"
            :value="item.id"
          />
        </el-select>
      </el-form-item> -->

          <el-form-item label="姓名" prop="xm">
            <el-input
              v-model="queryParams.xm"
              placeholder="请输入姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <!--      <el-form-item label="姓名拼音" prop="xmpy">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.xmpy"-->
          <!--          placeholder="请输入姓名拼音"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="曾用名" prop="cym">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.cym"-->
          <!--          placeholder="请输入曾用名"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="院系所部中心号" prop="yxsh">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.yxsh"-->
          <!--          placeholder="请输入院系所部中心号"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="专业号" prop="zyh">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.zyh"-->
          <!--          placeholder="请输入专业号"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="专业科类码" prop="zyklm">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.zyklm"-->
          <!--          placeholder="请输入专业科类码"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="培养方式码" prop="pyfsm">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.pyfsm"-->
          <!--          placeholder="请输入培养方式码"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="学生类别码" prop="xslbm">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.xslbm"-->
          <!--          placeholder="请输入学生类别码"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="研究方向码" prop="yjfxm">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.yjfxm"-->
          <!--          placeholder="请输入研究方向码"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="导师职工号" prop="dszgh">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.dszgh"-->
          <!--          placeholder="请输入导师职工号"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="获得学历方式码" prop="hdxlfsm">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.hdxlfsm"-->
          <!--          placeholder="请输入获得学历方式码"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--      <el-form-item label="学分制学生状况" prop="xfzxszk">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.xfzxszk"-->
          <!--          placeholder="请输入学分制学生状况"-->
          <!--          clearable-->
          <!--          size="small"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->

          <!-- <el-form-item label="年级" prop="nj">
        <el-input
          v-model="queryParams.nj"
          placeholder="请输入年级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:student:add']"
              >新增</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:student:edit']"
              >修改</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:student:remove']"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              :loading="exportLoading"
              @click="handleExport"
              v-hasPermi="['system:student:export']"
              >导出</el-button
            >
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="studentList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!--      <el-table-column label="主键id" align="center" prop="id" />-->
          <el-table-column label="学号" align="center" prop="xh" />
          <el-table-column label="姓名" align="center" prop="xm" />
          <el-table-column label="学制" align="center" prop="xz" />
          <el-table-column label="状态" align="center" prop="xsdqztmc" />
          <el-table-column label="入学年月" align="center" prop="rxny" />
          <el-table-column label="身份证号" align="center" prop="sfzh" />
          <el-table-column
            label="性别码"
            align="center"
            prop="xbm"
            :formatter="xbmFormat"
          />
          <el-table-column label="出生日期" align="center" prop="csrq" />
          <el-table-column label="出生地码" align="center" prop="csdm" />
          <el-table-column label="现住址" align="center" prop="xzz" />
          <el-table-column label="联系电话" align="center" prop="lxdh" />
          <el-table-column label="通信地址" align="center" prop="txdh" />
          <el-table-column label="电子信箱" align="center" prop="dzxx" />
          <el-table-column
            label="操作"
            width="150px"
            align="center"
            fixed="right"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:student:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:student:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 添加或修改学生信息对话框 -->
        <el-dialog
          :title="title"
          :visible.sync="open"
          width="500px"
          append-to-body
        >
          <!-- 添加学生信息的步骤条 -->
          <div>
            <el-steps :active="addActive" align-center finish-status="success">
              <el-step title="学生所在组织" description></el-step>
              <el-step title="学生基础信息" description></el-step>
              <el-step title="提交" description></el-step>
            </el-steps>

            <div>
              <div style="width: 50%; margin: 20px auto">{{ addText }}</div>
              <el-form
                ref="form"
                :model="form"
                :rules="rules"
                label-width="80px"
              >
                <div v-show="addActive === 0">
                  <!-- <el-form-item label="学年名称" prop="schoolYear">
              <el-select
                v-model="form.schoolYearId"
                placeholder="请选择学年"
                clearable
                size="small"
                style=" width: 100%;"
                @change="addTermByYear()"
              >
                <el-option
                  v-for="item in yearOptions"
                  :key="item.index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="学期名称" prop="termId">
              <el-select
                v-model="form.termId"
                placeholder="请选择学期"
                clearable
                size="small"
                style="width: 100%;"
                @change="addCollegeByTerm()"
              >
                <el-option
                  v-for="item in termNameOptions"
                  :key="item.index"
                  :label="item.termName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item> -->
                  <el-form-item label="学院名称" prop="collegeId">
                    <el-select
                      v-model="form.collegeId"
                      placeholder="请选择学院"
                      clearable
                      size="small"
                      style="width: 100%"
                      @change="
                        addMajorByCollege(), handleChange('form', 'collegeId')
                      "
                    >
                      <el-option
                        v-for="item in collegeOptions"
                        :key="item.index"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="专业名称" prop="majorId">
                    <el-select
                      v-model="form.majorId"
                      placeholder="请选择专业"
                      clearable
                      size="small"
                      style="width: 100%"
                      @change="
                        addClassByMajor(), handleChange('form', 'majorId')
                      "
                    >
                      <el-option
                        v-for="item in majorOptions"
                        :key="item.index"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="班级名称" prop="classesId">
                    <el-select
                      v-model="form.classesId"
                      placeholder="请选择班级"
                      clearable
                      size="small"
                      style="width: 100%"
                      @change="handleChange('form', 'classesId')"
                    >
                      <el-option
                        v-for="item in classOptions"
                        :key="item.index"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </div>

                <div v-show="addActive === 1">
                  <el-form-item label="学号" prop="xh">
                    <el-input v-model="form.xh" placeholder="请输入学号" />
                  </el-form-item>
                  <el-form-item label="姓名" prop="xm">
                    <el-input v-model="form.xm" placeholder="请输入姓名" />
                  </el-form-item>

                  <el-form-item label="入学年月" prop="rxny">
                    <el-input
                      v-model="form.rxny"
                      placeholder="请输入入学年月"
                    />
                  </el-form-item>
                  <el-form-item label="学制" prop="xz">
                    <el-input v-model="form.xz" placeholder="请输入学制" />
                  </el-form-item>
                  <el-form-item label="状态" prop="xsdqztdm">
                    <el-select v-model="form.xsdqztdm" placeholder="请选择状态">
                      <el-option
                        v-for="dict in studentStatus"
                        :key="dict.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="身份证号" prop="sfzh">
                    <el-input
                      v-model="form.sfzh"
                      placeholder="请输入身份证号"
                    />
                  </el-form-item>
                  <el-form-item label="性别码" prop="xbm">
                    <el-select v-model="form.xbm" placeholder="请选择性别码">
                      <el-option
                        v-for="dict in xbmOptions"
                        :key="dict.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      ></el-option>
                    </el-select>
                  </el-form-item>

                  <el-form-item label="出生日期" prop="csrq">
                    <el-input
                      v-model="form.csrq"
                      placeholder="请输入出生日期"
                    />
                  </el-form-item>
                  <el-form-item label="出生地码" prop="csdm">
                    <el-input
                      v-model="form.csdm"
                      placeholder="请输入出生地码"
                    />
                  </el-form-item>
                  <el-form-item label="现住址" prop="xzz">
                    <el-input v-model="form.xzz" placeholder="请输入现住址" />
                  </el-form-item>

                  <el-form-item label="联系电话" prop="lxdh">
                    <el-input
                      v-model="form.lxdh"
                      placeholder="请输入联系电话"
                    />
                  </el-form-item>

                  <el-form-item label="电子信箱" prop="dzxx">
                    <el-input
                      v-model="form.dzxx"
                      placeholder="请输入电子信箱"
                    />
                  </el-form-item>
                  <el-form-item label="主页地址" prop="zydz">
                    <el-input
                      v-model="form.zydz"
                      placeholder="请输入主页地址"
                    />
                  </el-form-item>
                </div>
              </el-form>
            </div>
          </div>

          <div class="neper">
            <el-button
              style="margin-top: 12px; margin-right: 10px"
              v-show="addActive > 0"
              @click="addper"
              >上一步</el-button
            >
            <el-button
              style="margin-top: 12px; margin-left: 10px"
              v-show="addActive < 2"
              @click="addnext"
              >下一步</el-button
            >
          </div>

          <span slot="footer" class="dialog-footer" v-show="addActive == 2">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="submitForm(), (addActive = 0)"
              >确 定</el-button
            >
          </span>
          <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
        </el-dialog>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  listMajor,
  listCollege,
  listYear,
  listStudent,
  getStudent,
  delStudent,
  addStudent,
  updateStudent,
  exportStudent,
} from "@/api/system/student";
import {
  listSchoolyear,
  getSchoolyear,
  delSchoolyear,
  addSchoolyear,
  updateSchoolyear,
  exportSchoolyear,
} from "@/api/org/schoolyear";

import { listClasses, getTree } from "@/api/org/classes";
import { listTerm } from "@/api/org/term";
import { org } from "@/views/mixins/org/index";
export default {
  name: "Student",
  mixins: [org],
  data() {
    return {
      // yearOptions: [{}],
      addText: "",
      // 步骤条参数
      addActive: 0,
      //班级信息
      classOptions: [
        {
          id: "",
          name: "",
        },
      ],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生信息表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别码字典
      xbmOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        majorId: null,
        collegeId: null,
        classesId: null,
        xh: null,
        xm: null,
        xmpy: null,
        cym: null,
        yxsh: null,
        zyh: null,
        zyklm: null,
        pyfsm: null,
        xslbm: null,
        yjfxm: null,
        dszgh: null,
        hdxlfsm: null,
        xfzxszk: null,
        xz: null,
        rxny: null,
        nj: null,
        bh: null,
        sfzh: null,
        xbm: null,
        xxm: null,
        csrq: null,
        csdm: null,
        jgm: null,
        mzm: null,
        zjxy: null,
        gatqm: null,
        jkzkm: null,
        hyzkm: null,
        xzz: null,
        hkszd: null,
        hkxzm: null,
        gbm: null,
        tc: null,
        lxdh: null,
        txdh: null,
        yzbm: null,
        dzxx: null,
        zydz: null,
      },
      // 表单参数
      form: {
        collegeId: null,
        majorId: null,
        classesId: null,
      },
      // 树形目录
      tree: [],
      defaultProps: {
        children: "list",
        label: "name",
      },
      // 表单校验
      rules: {
        xh: [{ required: true, message: "学号不能为空", trigger: "blur" }],
        collegeId: [{ required: true, message: "请选择学院", trigger: "blur" }],
        majorId: [{ required: true, message: "请选择专业", trigger: "blur" }],
        classesId: [{ required: true, message: "请选择班级", trigger: "blur" }],
      },
      addText: "",
      studentStatus: [],
    };
  },
  created() {
    this.getList();
    this.getTree();
    // this.getYearList();
    this.getCollegeList();
    this.getDicts("sys_sex").then((response) => {
      this.xbmOptions = response.data;
    });

    this.getDicts("student_status").then((response) => {
      this.studentStatus = response.data;
    });
  },
  methods: {
    resetClassOptions() {
      this.classOptions = [
        {
          id: "",
          name: "",
        },
      ];
    },
    //  // 搜索栏通过学年获取学期
    //  searchTermByYear() {
    //   this.queryParams.termId = "";
    //   this.queryParams.collegeId = "";
    //   this.queryParams.majorId = "";
    //   this.queryParams.classesId="";
    //   this.resetTermOptions();
    //   this.resetCollegeOptions();
    //   this.resetMajorOptions();
    //   this.resetClassOptions();
    //   console.log(this.queryParams.schoolYearId);
    //   if(this.queryParams.schoolYearId!==''){
    //     listTerm({ schoolYearId: this.queryParams.schoolYearId }).then((res) => {
    //       this.termNameOptions = res.rows;
    //       console.log('termOption: ', res.rows);
    //     });
    //   }
    // },
    //  // 添加或者修改框
    //  addTermByYear() {
    //   this.form.termId = "";
    //   this.form.collegeId = "";
    //   this.form.majorId = "";
    //   this.form.classesId = "";
    //    this.resetTermOptions();
    //   this.resetCollegeOptions();
    //   this.resetMajorOptions();
    //   this.resetClassOptions();
    //   console.log(this.form.schoolYearId);
    //   if(this.form.schoolYearId!==''){
    //     listTerm({ schoolYearId: this.form.schoolYearId }).then((res) => {
    //       this.termNameOptions = res.rows;
    //     });
    //   }
    // },
    // 用户打开弹出框的，初始化步骤条的信息
    closedDialog() {
      this.addActive = 0;
      this.addText = "以下为学生所在组织的基本信息:";
    },
    // 用户点击添加考试中的下一步按钮
    addnext() {
      this.addActive++;
      if (this.addActive === 0) {
        this.addText = "以下为学生所在组织的基本信息:";
      } else if (this.addActive === 1) {
        this.addText = "以下为学生个人相关信息:";
      } else if (this.addActive === 2) {
        this.addText = "请提点击确定提交学生信息";
      }
    },
    addper() {
      this.addActive--;
      if (this.addActive === 0) {
        this.addText = "以下为学生所在组织的基本信息:";
      } else if (this.addActive === 1) {
        this.addText = "以下为学生个人相关信息:";
      } else if (this.addActive === 2) {
        this.addText = "请提点击确定提交学生信息";
      }
    },
    // 根据选取的专业获取专业下面的班级
    searchClassByMajor() {
      console.log(" searchClassByMajor");
      this.queryParams.classesId = "";
      this.resetClassOptions();
      if (this.queryParams.majorId !== "") {
        listClasses({
          majorId: this.queryParams.majorId,
        }).then((res) => {
          this.classOptions = res.rows;
        });
      }
    },
    // 添加 通过专业搜索班级
    addClassByMajor() {
      console.log(" addClassByMajor");
      console.log("majorId: ", this.form.majorId);
      this.form.classesId = "";
      this.resetClassOptions();
      console.log("classOptions: ", this.classOptions);
      if (this.form.majorId !== "") {
        listClasses({
          majorId: this.form.majorId,
        }).then((res) => {
          this.classOptions = res.rows;
          console.log("rows: ", res.rows);
          console.log("classOptions: ", this.classOptions);
        });
      }
    },

    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then((response) => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取树形目录
    getTree() {
      getTree("").then((res) => {
        console.log("tree: ", res);
        this.tree = res;
      });
    },
    // 树形目录点击后获取对应的学生信息
    handleNodeClick(data) {
      console.log("treeData: ", data);
      const flag = data.typeFlag;
      switch (flag) {
        case "college":
          this.queryParams.collegeId = data.id;
          this.queryParams.majorId = null;
          this.queryParams.classesId = null;
          break;
        case "major":
          this.queryParams.majorId = data.id;
          this.queryParams.collegeId = null;
          this.queryParams.classesId = null;
          break;
        case "classes":
          this.queryParams.classesId = data.id;
          this.queryParams.majorId = null;
          this.queryParams.collegeId = null;
          break;
        default:
          break;
      }
      /** 查询学生信息列表 */
      this.getList();
    },

    // 性别码字典翻译
    xbmFormat(row, column) {
      return this.selectDictLabel(this.xbmOptions, row.xbm);
    },
    // 取消按钮
    cancel() {
      this.addActive = 0;
      this.addText = "以下为学生所在组织的基本信息:";
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        classesId: null,
        userId: null,
        xh: null,
        xm: null,
        xmpy: null,
        cym: null,
        yxsh: null,
        zyh: null,
        zyklm: null,
        pyfsm: null,
        xslbm: null,
        yjfxm: null,
        dszgh: null,
        hdxlfsm: null,
        xfzxszk: null,
        xz: null,
        rxny: null,
        nj: null,
        bh: null,
        sfzh: null,
        xbm: null,
        xxm: null,
        csrq: null,
        csdm: null,
        jgm: null,
        mzm: null,
        zjxy: null,
        gatqm: null,
        jkzkm: null,
        hyzkm: null,
        xzz: null,
        hkszd: null,
        hkxzm: null,
        gbm: null,
        tc: null,
        lxdh: null,
        txdh: null,
        yzbm: null,
        dzxx: null,
        zydz: null,
        zp: null,
        xz: null,
      };
      this.resetForm("form");
      this.closedDialog();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      let that = this;
      getStudent(id).then((response) => {
        that.form = response.data;
        console.log("获取的待修改的学生信息form:", that.form);
        that.open = true;
        that.title = "修改学生信息";
        that.majorOptions[0].id = response.data.majorId;
        that.majorOptions[0].name = response.data.majorName;
        that.classOptions[0].id = response.data.classesId;
        that.classOptions[0].name = response.data.className;
        console.log("majorOptions: ", that.majorOptions[0]);
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateStudent(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除学生信息编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delStudent(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有学生信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportStudent(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped>
.neper {
  display: flex;
  margin-left: 50%;
  transform: translateX(-50%);
}
</style>
